//
//  ViewController.m
//  内涵段子测试
//
//  Created by hanpeng on 15-11-24.
//  Copyright (c) 2015年 hanpeng. All rights reserved.
//

#import "ViewController.h"
#import "AFNetworking.h"
#import "MJExtension.h"
#import "HPDataModel.h"
#import "HPGroupModel.h"
#import "HPDataArrayModel.h"
#import <MediaPlayer/MediaPlayer.h>
@interface ViewController ()
@property(nonatomic,strong)UIView *playVcview;

@end

@implementation ViewController

-(UIView *)playVcview
{
    if (!_playVcview) {
        _playVcview = [[UIView alloc]init];
        
              _playVcview.frame = CGRectMake(0, 0,320,206);
        
        
      
        _playVcview.backgroundColor = [UIColor redColor];
    }
    return _playVcview;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
     [self.view addSubview:self.playVcview];

    
  }
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSMutableDictionary * params  =[NSMutableDictionary dictionary ];
    params[@"count"]=@1;

    AFHTTPSessionManager * mgr = [AFHTTPSessionManager manager];
    [mgr GET:@"http://ic.snssdk.com/neihan/stream/mix/v1/" parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
      
        NSDictionary * dict = responseObject[@"data"];
        
        NSArray * dataArr = dict[@"data"];
        
        NSMutableArray * arr = [NSMutableArray array];
        for (NSDictionary * dict in dataArr) {
            HPDataArrayModel * datamodel = [HPDataArrayModel objectWithKeyValues:dict];
            if ( datamodel.group.mp4_url) {
                NSLog(@"%@", datamodel.group.mp4_url);
                MPMoviePlayerViewController *playVc = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL URLWithString:datamodel.group.mp4_url]];
           
                playVc.view.frame = self.playVcview.frame;
                [playVc prefersStatusBarHidden ];
         
                [self.playVcview addSubview:playVc.view];
        
                
                
               
//                [self presentViewController:playVc animated:YES completion:nil];
                
                NSLog(@"%d..%d",datamodel.group.video_width.intValue,datamodel.group.video_height.intValue);
                
            }
           
            [arr addObject:datamodel];
        }
        
       
        
        
        
        NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject ] ;
        
        
        
        
        
        NSString * file = [path stringByAppendingPathComponent:@"hanpeng.plist"];
        
        
        
        NSFileManager *fm = [NSFileManager defaultManager];
        
        
        
        if ([fm createFileAtPath:file contents:nil attributes:nil] ==YES) {
            
            
            
            [responseObject writeToFile:file atomically:YES];
            
      
            
        }
        
        
        

        
        
        
        
        
        
        
        
      
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"请求失败");
    }];




}

@end
